﻿using System;
using System.IO;
using System.Management;
using System.Security.Cryptography;
using System.Text;

namespace XC.Keys
{
    internal class DES
    {
        private byte[] keyvi = new byte[] { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 };
        private string Pwd = "20190422";
        /// <summary>
        /// 解密
        /// </summary>
        /// <param name="securityContent"></param>
        /// <returns></returns>
        public string DesDecrypt(string securityContent)
        {
            try
            {
                var bytes = Convert.FromBase64String(securityContent);
                var key = Encoding.UTF8.GetBytes(Pwd.PadLeft(8, '0').Substring(0, 8));
                using (MemoryStream ms = new MemoryStream())
                {
                    var descrypt = new DESCryptoServiceProvider();
                    var data = descrypt.CreateDecryptor(key, keyvi);
                    CryptoStream cs = new CryptoStream(ms, data, CryptoStreamMode.Write);
                    cs.Write(bytes, 0, bytes.Length);
                    cs.FlushFinalBlock();
                    return Encoding.UTF8.GetString(ms.ToArray());
                }
            }
            catch (Exception)
            {

                return string.Empty;
            }
        }



        public string GetCpuID()
        {
            try
            {
                string cpuInfo = "";//cpu序列号 
                ManagementClass mc = new ManagementClass("Win32_Processor");
                ManagementObjectCollection moc = mc.GetInstances();
                foreach (ManagementObject mo in moc)
                {
                    cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
                }
                moc = null;
                mc = null;
                return cpuInfo;
            }
            catch
            {
                return "unknow";
            }
            finally
            {
            }
        }

    }

}
